package com.nisco.dms.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.nisco.dms.entity.Permission;
import com.nisco.dms.repository.PermissionDao;
import com.nisco.dms.util.dwz.Page;
import com.nisco.dms.util.dwz.PageUtils;

@Component
@Transactional(readOnly=true)
public class PermissionService extends BaseService<Permission, String> 
{
	@Autowired
	private PermissionDao permissionDao;

	/**
	 * 必须提供空的构造函数以便spring实例化
	 */
	public PermissionService()
	{
	}

	/**
	 * 
	 * @param permissionDao
	 */
	@Autowired
	public PermissionService(PermissionDao permissionDao)
	{
		super((JpaRepository<Permission, String>)permissionDao);
		this.permissionDao = permissionDao;
	}
	
	/**
	 * 根据模块ID查询权限清单
	 * @param moduleId
	 * @param page
	 * @return
	 */
	public  List<Permission> findPermissionsByModuleId(String moduleId,Page page)
	{
		org.springframework.data.domain.Page<Permission> pagePermission = permissionDao.findByProgramId(moduleId, PageUtils.createPageable(page));
		PageUtils.injectPageProperties(page, pagePermission);
		return pagePermission.getContent();
	}
	
	public  List<Permission> findByModuleId(String moduleId)
	{
		return permissionDao.findByProgramId(moduleId);
	} 

}
